package secondarysort;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.WritableComparable;

public class Intpair implements WritableComparable<Intpair> {
	
	int first;
	int second;
	
	
	public void set (int left,int right){
		left = this.first;
		right = this.second;
	}
	
	

	public int getFirst() {
		return first;
	}

	public void setFirst(int first) {
		this.first = first;
	}

	public int getSecond() {
		return second;
	}

	public void setSecond(int second) {
		this.second = second;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + first;
		result = prime * result + second;
		return result;
	}



	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Intpair other = (Intpair) obj;
		if (first != other.first)
			return false;
		if (second != other.second)
			return false;
		return true;
	}

	public void write(DataOutput out) throws IOException {
		out.writeInt(first);
		out.write(second);
		
	}

	public void readFields(DataInput in) throws IOException {
		first = in.readInt();
		second = in.readInt();
		
	}
	
	
	
	//key 的比较
	public int compareTo(Intpair o) {
		
		if(first != o.first){
			return first < o.first?-1:1;
		}else if(second!=o.second){
			return second < o.second?-1:1;
		}else{
			return 0;
		}
		
	}



	@Override
	public String toString() {
		return "Intpair [first=" + first + ", second=" + second + "]";
	}





}
